home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 2
/
Mac Magazin and MacEasy Magazine CD - Issue 02.iso
/
Sharewarebibliothek
/
Applikationen
/
Alpha.5.81 folder
/
Tcl
/
SystemCode
/
wordCompletion.tcl
< prev
Wrap
Text File
|
1994-04-27
|
3KB
|
82 lines
#===========================================================================
# 'Word Completion, in the spirit of Paul van Mulbregt's BBXT.
#
# Composed by Mark Nagata (nagata@kurims.kyoto-u.ac.jp)
# for Alpha 5.76, 4/22/94.
#
#================================================================================
proc wordCompletion {} {
set pos [getPos]
backwardWord
set start [getPos]
set one [getText $start $pos]
set len [expr $pos-$start]
set pat [append one {[a-zA-Z0-9_]+}]
set start [expr $start-1]
if {![catch {search -f 0 -r 1 -i 0 -m 1 -- $pat $start} data]} {
set beg [expr [lindex $data 0]+$len]
set end [lindex $data 1]
set txt [getText $beg $end]
goto $pos
insertText $txt
message "found above."
return
}
if {![catch {search -f 1 -r 1 -i 0 -m 1 -- $pat $pos} data]} {
set beg [expr [lindex $data 0]+$len]
set end [lindex $data 1]
set txt [getText $beg $end]
goto $pos
insertText $txt
message "found below."
return
}
goto $pos
backwardWordSelect
}
bind F1 wordCompletion
# This is all due to the idea of Paul van Mulbregt. In his documentation
# of his BBEdit BBExtension (info-mac/text/bbedit-fl-package-11.hqx),
# he explains:
#
# -- From the documentation written by --
# -- Paul van Mulbregt (paulvm@dragonsys.com) --
#
# Word Completion
#
# This extension saves typing, as well as making sure variable names are
# correct. While typing the following C code, there is no need to type all
# of the second occurrence of verySpecialInt. One could copy and paste, but
# another way is to type a few letters, and select the Word Completion
# Extension.
#
# int verySpecialInt = 10;
# while(verySp
#
#
# becomes
#
# int verySpecialInt = 10;
# while(verySpecialInt
#
#
#
# Word Completion will look back in the code to find the first match and then
# extend the current occurrence to match the previous occurrence. If a match
# is not found looking backwards, then it looks forwards. If not found
# forwards, the word is selected. This is a quick way to save on typing,
# good for helping prevent RSI, but perhaps more importantly, to make sure
# that variable names are spelt correctly.
#
# There is no user interface for Word Completion.
#
# The usefulness of this extension is greatly enhanced if the extension is
# bound to a key!
#
# -- end of Paul van Mulbregt's explanation. --